/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dawnland03.ui.model;

import dawnland03.ui.model.entity.UIEntityModel;
import javafx.scene.CustomNode;
import javafx.scene.Node;
import javafx.scene.Group;
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.layout.Stack;
import javafx.scene.layout.VBox;
import dawnland03.model.entity.attribute.PhysicalAttribute;
import javafx.scene.layout.HBox;
import dawnland03.model.item.ItemType;
import javafx.scene.layout.Panel;
import javafx.scene.layout.Container;

/**
 * @author user
 */

public class UIEntityPanel extends CustomNode{
    public var uiEntityModel: UIEntityModel;

    var group : Group = Group {};

    init {
        def rectangle = Rectangle {
            width: 200
            height: 200
            fill: Color.WHEAT
            stroke: Color.DARKBLUE
        }
        def idText = Text {
            content: bind "Id: {uiEntityModel.id}";
            fill: Color.ROYALBLUE;
            font: Font.font("Courier", FontWeight.BOLD, 20)
        }

        //physical attributes
        def physicalAttributesNames = VBox{};
        for(physicalAttribute in PhysicalAttribute.values()){
           def physicalAttributeText = Text {
               content: "{physicalAttribute}:";
               fill: Color.ROYALBLUE;
               font: Font.font("Courier", FontWeight.BOLD, 20)
           }
           insert physicalAttributeText into physicalAttributesNames.content;
        }
        def physicalAttributesValues = VBox{};
        for(physicalAttribute in PhysicalAttribute.values()){
           def physicalAttributeValue = Text {
               content: bind "{%3.2f uiEntityModel.getPhysicalAttribute(physicalAttribute)}";
               fill: Color.ROYALBLUE;
               font: Font.font("Courier", FontWeight.BOLD, 20)
           }
           insert physicalAttributeValue into physicalAttributesValues.content;
        }
        def physicalAttributes = HBox{
           content: [physicalAttributesNames, physicalAttributesValues]
        };

        //item quantities
        def itemNames = VBox{};
        for(itemType in ItemType.values()){
           def itemNameText = Text {
               content: "{itemType}:";
               fill: Color.ROYALBLUE;
               font: Font.font("Courier", FontWeight.BOLD, 20)
           }
           insert itemNameText into itemNames.content;
        }
        def itemQuantityValues = VBox{};
        for(itemType in ItemType.values()){
           def itemQuantityValue = Text {
               content: bind "{uiEntityModel.getItemQuantity(itemType)}";
               fill: Color.ROYALBLUE;
               font: Font.font("Courier", FontWeight.BOLD, 20)
           }
           insert itemQuantityValue into itemQuantityValues.content;
        }
        def itemQuantities = HBox{
           content: [itemNames, itemQuantityValues]
        };

        def width = 200;
        def stack = Stack{
            content:[rectangle,
            Panel {
                content: [idText, physicalAttributes, itemQuantities]
                onLayout: function(){
                    def idTextHeight = 20;
                    def physicalAttributesHeight = PhysicalAttribute.values().length*30;
                    def itemsHeight = ItemType.values().length*30;
                    Container.layoutNode(idText, 0, 0, width, idTextHeight);
                    Container.layoutNode(physicalAttributes, 0, idTextHeight, width, idTextHeight+physicalAttributesHeight);
                    Container.layoutNode(itemQuantities, 0, idTextHeight+physicalAttributesHeight, width, idTextHeight+physicalAttributesHeight+itemsHeight);
                }
            }]
        }
        insert stack into group.content;
    }


    override function create(): Node {
        return group;
    }
}
